﻿<%@ Page Title="" Language="C#" MasterPageFile="~/TsSite.Master" AutoEventWireup="true" CodeBehind="ManageUsers.aspx.cs" Inherits="TireService.Web.View.AdminView.ManageUsers" %>
<%@ Register Assembly="DevExpress.Web.v11.1, Version=11.1.12.0, Culture=neutral, PublicKeyToken=b88d1754d700e49a" Namespace="DevExpress.Web.ASPxCallback" TagPrefix="dx" %>
<%@ Register Assembly="DevExpress.Web.ASPxEditors.v11.1, Version=11.1.12.0, Culture=neutral, PublicKeyToken=b88d1754d700e49a" Namespace="DevExpress.Web.ASPxEditors" TagPrefix="dx" %>
<%@ Register Assembly="DevExpress.Web.v11.1, Version=11.1.12.0, Culture=neutral, PublicKeyToken=b88d1754d700e49a" Namespace="DevExpress.Web.ASPxCallbackPanel" TagPrefix="dx" %>
<%@ Register Assembly="DevExpress.Web.v11.1, Version=11.1.12.0, Culture=neutral, PublicKeyToken=b88d1754d700e49a" Namespace="DevExpress.Web.ASPxPopupControl" TagPrefix="dx" %>
<%@ Register assembly="DevExpress.Web.v11.1, Version=11.1.12.0, Culture=neutral, PublicKeyToken=b88d1754d700e49a" namespace="DevExpress.Web.ASPxPanel" tagprefix="dx" %>
<%@ Register Assembly="DevExpress.Web.ASPxGridView.v11.1, Version=11.1.12.0, Culture=neutral, PublicKeyToken=b88d1754d700e49a" Namespace="DevExpress.Web.ASPxGridView" TagPrefix="dx" %>
<%@ Register Assembly="DevExpress.Web.ASPxGridView.v11.1.Export, Version=11.1.12.0, Culture=neutral, PublicKeyToken=b88d1754d700e49a" Namespace="DevExpress.Web.ASPxGridView.Export" TagPrefix="dx" %>

<asp:Content ID="Content1" ContentPlaceHolderID="head" runat="server">

</asp:Content>


<asp:Content ID="Content2" ContentPlaceHolderID="ContentPlaceHolder1" runat="server">

    <table cellpadding="0" cellspacing="2" border="0">
        <tr>
            <td>
                <img id="imgManageUsers" alt="" src="~/Images/Medium/businessman.png" runat="server" style="width: 32px; height: 32px" />
            </td>
            <td valign="middle">
                <h3><asp:Label ID="lblManageUsers" runat="server" Text="Bruger administration"></asp:Label></h3>
            </td>
        </tr>
    </table>

    <!-- Javascript of action dropdown list -->
    <script language="javascript" type="text/javascript">

        // Function that handles actions selected in dropdown list
        function ActionClicked() {

            // Get selected action from dropdownlist
            var id = ddlAction.GetValue();

            if (id != null && id != 0) {
                if (id == 1) {
                    // Show create user modal popup
                    pcCreateUser.Show();
                }
                if (id == 2) {
                    // Get selected user to reset from selection in gridview
                    gvUser.GetRowValues(gvUser.GetFocusedRowIndex(), 'UserName', ResetUserGetSelectedUser);
                }
                if (id == 3) {
                    // Get selected user to edit role assignement for, from selection in gridview
                    gvUser.GetRowValues(gvUser.GetFocusedRowIndex(), 'UserName', ChangeRolesGetSelectedUser);
                }

            }
            else {
                alert('Ingen handling valgt');
            }
        }

        function ResetUserGetSelectedUser(value) {
            if (value == null) {
                alert('Ingen bruger valgt - venligst vælg en bruger og prøv igen.');
            }
            else {

                // Set label value with username
                lblSelectedUserNameValue.SetText(value);

                // Show reset user modal popup
                pcResetUser.Show();
            }
        }

        function ChangeRolesGetSelectedUser(value) {
            if (value == null) {
                alert('Ingen bruger valgt - venligst vælg en bruger og prøv igen.');
            }
            else {

                // Set label value with username
                lblRoleAssignmentSelectedUserNameValue.SetText(value);

                // Show user change role assignment modal popup
                pcChangeUserRoleAssignment.Show();
            }
        }

    </script>

    <table border="0" cellspacing="0" cellpadding="5" width="100%">
        <tr>
            <td style="width:150px">
                <dx:ASPxComboBox ID="ddlAction" ClientInstanceName="ddlAction" runat="server" Width="150px">
                    <Items>
                        <dx:ListEditItem Selected="true" Value="0" Text="-- Handling --" />
                        <dx:ListEditItem Value="1" Text="Opret bruger" />
                        <dx:ListEditItem Value="2" Text="Reset bruger" />
                        <dx:ListEditItem Value="3" Text="Rediger rolle tildeling" />
                    </Items>
                </dx:ASPxComboBox>
            </td>
            <td style="width:75px">
                <dx:ASPxButton ID="btnSubmitAction" runat="server" Text="Udfør" AutoPostBack="False" UseSubmitBehavior="False" Width="75px">
                    <ClientSideEvents Click="function(s, e) { ActionClicked(); }" />
                </dx:ASPxButton>
            </td>
            <td style="width:150px">
                <dx:ASPxComboBox ID="ddlExport" ClientInstanceName="ddlExport" runat="server" Width="150px">
                    <Items>
                        <dx:ListEditItem Selected="True" Value="0" Text="Export pdf" />
                        <dx:ListEditItem Value="1" Text="Export xls" />
                        <dx:ListEditItem Value="2" Text="Export csv" />
                        <dx:ListEditItem Value="3" Text="Export rtf" />
                    </Items>
                </dx:ASPxComboBox>
            </td>
            <td style="width:75px">
                <dx:ASPxButton ID="btnExport" runat="server" Text="Exporter" OnClick="btnExport_Click" Width="75px" >
                </dx:ASPxButton>
            </td>
            <td align="right">
                <asp:Label ID="lblView" runat="server" Text="Visning"></asp:Label>
                <asp:Label ID="lblPageSize" runat="server" Text="Antal linjer pr side"></asp:Label>
                <asp:DropDownList ID="ddlPageSize" runat="server" AutoPostBack="true">
                    <asp:ListItem Value="10">10</asp:ListItem>
                    <asp:ListItem Value="25">25</asp:ListItem>
                    <asp:ListItem Value="50">50</asp:ListItem>
                    <asp:ListItem Value="100">100</asp:ListItem>
                </asp:DropDownList>
            </td>
        </tr>
    </table>          
    <hr />

    <dx:ASPxGridView ID="gvUser" runat="server" ClientInstanceName="gvUser" 
        KeyFieldName="UserId" Width="100%" AutoGenerateColumns="False" EnableCallBacks="True" >
        <SettingsLoadingPanel Text="Henter&amp;hellip;" />
        <Settings ShowHeaderFilterButton="true" ShowGroupPanel="false" ShowFilterRow="True" />
        <SettingsPager AlwaysShowPager="False" PageSize="25" Position="TopAndBottom">
            <Summary 
                AllPagesText="Sider: {0} - {1} ({2} brugere)" 
                Text="Side {0} af {1} ({2} brugere)" />
        </SettingsPager>
        <SettingsText ConfirmDelete="Vil du slette denne bruger?" GroupPanel="Træk kolonne hertil for at gruppere efter den" HeaderFilterShowAll="Vis alle" />
        <SettingsBehavior ProcessFocusedRowChangedOnServer="false" AllowFocusedRow="true" AllowGroup="false" AllowDragDrop="false" />
                            
        <Columns>
            <%--<dx:GridViewCommandColumn ShowSelectCheckbox="True" VisibleIndex="0">
                    <HeaderTemplate>
                        <input type="checkbox" onclick="gvCustomer.SelectAllRowsOnPage(this.checked);" style="vertical-align:middle;" title="Vælg/Fravælg alle linjer på siden"></input>
                    </HeaderTemplate>
                    <HeaderStyle Paddings-PaddingTop="1" Paddings-PaddingBottom="1" 
                        HorizontalAlign="Center">
                    <Paddings PaddingTop="1px" PaddingBottom="1px"></Paddings>
                    </HeaderStyle>
            </dx:GridViewCommandColumn>--%>
            <dx:GridViewDataColumn FieldName="UserName" VisibleIndex="0" Caption="Brugernavn">
            </dx:GridViewDataColumn>
            <dx:GridViewDataColumn FieldName="Email" VisibleIndex="1" Caption="Email">
            </dx:GridViewDataColumn>
            <dx:GridViewDataColumn FieldName="CustomerName" VisibleIndex="2" Caption="Kundenavn">
            </dx:GridViewDataColumn>
            <%--<dx:GridViewDataHyperLinkColumn FieldName="CustId" VisibleIndex="3" Caption="Kundenr">
                <PropertiesHyperLinkEdit NavigateUrlFormatString="~/View/CustomerView/EditCustomer.aspx?CustomerId={0}" TextField="CustId">
                </PropertiesHyperLinkEdit>
            </dx:GridViewDataHyperLinkColumn>--%>
            <dx:GridViewDataColumn FieldName="IsLockedOut" VisibleIndex="4" Caption="Låst">
            </dx:GridViewDataColumn>
            <dx:GridViewDataColumn FieldName="CreateDate" VisibleIndex="5" Caption="Oprettet">
            </dx:GridViewDataColumn>
            <dx:GridViewDataColumn FieldName="LastLoginDate" VisibleIndex="6" Caption="Sidst logget ind">
            </dx:GridViewDataColumn>
            <dx:GridViewDataColumn FieldName="LastLockoutDate" VisibleIndex="7" Caption="Sidst låst">
            </dx:GridViewDataColumn>
            <dx:GridViewDataColumn FieldName="Roles" VisibleIndex="8" Caption="Antal roller">
            </dx:GridViewDataColumn>
        </Columns>
                            
    </dx:ASPxGridView>
                
    <dx:ASPxGridViewExporter ID="gvExport" runat="server" GridViewID="gvUser">
    </dx:ASPxGridViewExporter>


    <!-- Javascript for create new user -->
    <script language="javascript" type="text/javascript">

        function UserTypeSelected() {
            var usertype = ddlUserType.GetValue();
            
            if (usertype == 0) {
                alert("Vælg bruger type");
                return;
            }
            if (usertype == 1) {
                pInternalUser.SetVisible(true);
                pCustomerUser.SetVisible(false);
                btnCreateCustomerUser.SetVisible(false);
                btnCreateInternalUser.SetVisible(true);
            }
            if (usertype == 2) {
                pInternalUser.SetVisible(false);
                pCustomerUser.SetVisible(true);
                btnCreateCustomerUser.SetVisible(true);
                btnCreateInternalUser.SetVisible(false);
            }
            if (usertype == 3) {
                pInternalUser.SetVisible(false);
                pCustomerUser.SetVisible(true);
                btnCreateCustomerUser.SetVisible(true);
                btnCreateInternalUser.SetVisible(false);
            }
        }

        // Function that handles create user in database
        function CreateInternalUser() {

            // Validate values
            var usertype = ddlUserType.GetValue();

            if (usertype == 0) {
                alert("Vælg bruger type");
                return;
            }

            txtUserName.Validate();
            txtPassword.Validate();
            txtRepeatPassword.Validate();

            if (txtPassword.GetText() != txtRepeatPassword.GetText()) {
                alert("Adgangskode og gentag adgangskode er ikke ens");
                return;
            }

            if (cbAdministration.GetChecked() == false & cbCasehandler.GetChecked() == false & cbServiceTechnician.GetChecked() == false) {
                alert("Ingen rolle tildelt ny bruger");
                return;
            }

            var isFormValid = ASPxClientEdit.ValidateGroup("CreateUser");
            if (isFormValid) {

                var values = "CreateInternalUser" + '|' + txtUserName.GetText() + '|' + txtPassword.GetText() + '|' + cbEmailUserCreateInfo.GetChecked() + '|' + cbAdministration.GetChecked() + '|' + cbCasehandler.GetChecked() + '|' + cbServiceTechnician.GetChecked();

                callbackCreateUserPanel.PerformCallback(values);
            }
        }

        // Function that handles create user in database
        function CreateCustomerUser() {

            // Validate values
            var usertype = ddlUserType.GetValue();

            if (usertype == 0) {
                alert("Vælg bruger type");
                return;
            }

            ddlCustomer.Validate();
            txtUserName.Validate();
            txtPassword.Validate();
            txtRepeatPassword.Validate();

            if (txtPassword.GetText() != txtRepeatPassword.GetText()) {
                alert("Adgangskode og gentag adgangskode er ikke ens");
                return;
            }

            var isFormValidCustomerUser = ASPxClientEdit.ValidateGroup("SelectCustomer");
            var isFormValid = ASPxClientEdit.ValidateGroup("CreateUser");
            if (isFormValid & isFormValidCustomerUser) {

                var values = "CreateCustomerUser" + '|' + txtUserName.GetText() + '|' + txtPassword.GetText() + '|' + cbEmailUserCreateInfo.GetChecked() + '|' + ddlCustomer.GetValue() + '|' + cbBusinessCustomer.GetChecked();

                callbackCreateUserPanel.PerformCallback(values);
            }
        }

        function OnCallbackCreateUserComplete(s, e) {
            // Reset form
            // TODO: Write code

            // Hide modal popup
            pcCreateUser.Hide();

            // Refresh gridview with users
            gvUser.PerformCallback();

            alert('Bruger blev oprettet');
        }

        function CreateUserCallBackError(s, e) {
            // Hide modal popup
            pcCreateUser.Hide();

            alert('Fejl opstod: ' + e.message);
        }

    </script>

    <!-- Modalpopup: Create User -->
    <dx:ASPxPopupControl ID="pcCreateUser" Modal="true" runat="server" Height="1px" AutoUpdatePosition="true"
        PopupHorizontalAlign="WindowCenter" PopupVerticalAlign="WindowCenter"
        AllowDragging="True" ClientInstanceName="pcCreateUser" Left="100" Top="100"
        CloseAction="CloseButton" Width="175px" HeaderText="Opret bruger">
        <ContentCollection>
            <dx:PopupControlContentControl ID="PopupControlContentControl1" runat="server">
                <dx:ASPxCallbackPanel ID="callbackCreateUserPanel" ClientInstanceName="callbackCreateUserPanel" runat="server"
                    Width="320px" Height="100px" OnCallback="callbackCreateUserPanel_Callback" RenderMode="Table">
                    <ClientSideEvents EndCallback="OnCallbackCreateUserComplete" CallbackError="CreateUserCallBackError" />
                    <PanelCollection>
                        <dx:PanelContent ID="PanelContent1" runat="server">
                            
                            <asp:Panel runat="server" ID="pCreateUser">
                                <table>
                                    <tr>
                                        <td>
                                            <dx:ASPxLabel ID="lblUserType" runat="server" Text="Type">
                                            </dx:ASPxLabel>
                                        </td>
                                        <td>
                                            <dx:ASPxComboBox ID="ddlUserType" ClientInstanceName="ddlUserType" runat="server">
                                                <Items>
                                                    <dx:ListEditItem Value="0" Text="- Vælg bruger type -" />
                                                    <dx:ListEditItem Value="1" Text="Intern bruger" />
                                                    <dx:ListEditItem Value="2" Text="Privatkunde bruger" />
                                                    <dx:ListEditItem Value="3" Text="Erhvervskunde/Leasing bruger" />
                                                </Items>
                                                <ClientSideEvents SelectedIndexChanged="function(s, e) { UserTypeSelected(); }" />
                                            </dx:ASPxComboBox>
                                        </td>
                                    </tr>
                                </table>

                                <dx:ASPxPanel ID="pInternalUser" ClientInstanceName="pInternalUser" runat="server" Width="320px" ClientVisible="false">
                                    <PanelCollection>
                                        <dx:PanelContent>
                                            <table>
                                                <tr>
                                                    <td colspan="2">
                                                        <dx:ASPxLabel ID="lblRole" runat="server" Text="Roller">
                                                        </dx:ASPxLabel>
                                                    </td>
                                                </tr>
                                                <tr>
                                                    <td colspan="2">
                                                        <dx:ASPxCheckBox ID="cbAdministration" ClientInstanceName="cbAdministration" runat="server" Text="Administrator">
                                                        </dx:ASPxCheckBox>
                                                        <dx:ASPxCheckBox ID="cbCasehandler" ClientInstanceName="cbCasehandler" runat="server" Text="Sagsbehandler">
                                                        </dx:ASPxCheckBox>
                                                        <dx:ASPxCheckBox ID="cbServiceTechnician" ClientInstanceName="cbServiceTechnician" runat="server" Text="ServiceTekniker">
                                                        </dx:ASPxCheckBox>
                                                    </td>
                                                </tr>
                                            </table>
                                        </dx:PanelContent>
                                    </PanelCollection>
                                </dx:ASPxPanel>
                                <dx:ASPxPanel ID="pCustomerUser" ClientInstanceName="pCustomerUser" runat="server" Width="320px" ClientVisible="false">
                                    <PanelCollection>
                                        <dx:PanelContent>
                                            <table>
                                                <tr>
                                                    <td>
                                                        <dx:ASPxLabel ID="lblCustomer" runat="server" Text="Kunde">
                                                        </dx:ASPxLabel>
                                                    </td>
                                                    <td>
                                                        <dx:ASPxComboBox ID="ddlCustomer" ClientInstanceName="ddlCustomer" IncrementalFilteringMode="StartsWith" TextFormatString="{0} {1}"
                                                            DropDownWidth="350" DropDownStyle="DropDownList" runat="server" ValueField="CustomerId">
                                                            <ValidationSettings CausesValidation="true" ValidationGroup="SelectCustomer" RequiredField-IsRequired="true" RequiredField-ErrorText="Vælg kunde" SetFocusOnError="true" ErrorDisplayMode="ImageWithTooltip">
                                                                <RequiredField IsRequired="True" ErrorText="V&#230;lg kunde"></RequiredField>
                                                            </ValidationSettings>
                                                            <Columns>
                                                                <dx:ListBoxColumn FieldName="CustomerId" Caption="Kundenr" Width="100px" />
                                                                <dx:ListBoxColumn FieldName="CompanyName" Caption="Navn" Width="100px" />
                                                                <dx:ListBoxColumn FieldName="Name" Caption="Navn" Width="150px" />
                                                            </Columns>
                                                        </dx:ASPxComboBox>
                                                    </td>
                                                    <td>
                                                        <dx:ASPxCheckBox ID="cbBusinessCustomer" ClientInstanceName="cbBusinessCustomer" runat="server" Text="Erhvervskunde?">
                                                        </dx:ASPxCheckBox>
                                                    </td>
                                                </tr>
                                            </table>
                                        </dx:PanelContent>
                                    </PanelCollection>
                                </dx:ASPxPanel>
                                <table>
                                    <tr>
                                        <td>
                                            <dx:ASPxLabel ID="lblUserName" runat="server" Text="Email / Brugernavn">
                                            </dx:ASPxLabel>
                                        </td>
                                        <td>
                                            <dx:ASPxTextBox ID="txtUserName" ClientInstanceName="txtUserName" runat="server" Width="170px">
                                                <ValidationSettings CausesValidation="true" ValidationGroup="CreateUser" RequiredField-IsRequired="true" RequiredField-ErrorText="Indtast brugernavn" SetFocusOnError="true" ErrorDisplayMode="ImageWithTooltip">
                                                    <RequiredField IsRequired="True" ErrorText="Indtast brugernavn"></RequiredField>
                                                </ValidationSettings>
                                            </dx:ASPxTextBox>
                                        </td>
                                    </tr>
                                    <tr>
                                        <td>
                                            <dx:ASPxLabel ID="lblPassword" runat="server" Text="Adgangskode">
                                            </dx:ASPxLabel>
                                        </td>
                                        <td>
                                            <dx:ASPxTextBox ID="txtPassword" ClientInstanceName="txtPassword" Password="true" runat="server" Width="170px">
                                                <ValidationSettings CausesValidation="true" ValidationGroup="CreateUser" RequiredField-IsRequired="true" RequiredField-ErrorText="Indtast adgangskode" SetFocusOnError="true" ErrorDisplayMode="ImageWithTooltip">
                                                    <RequiredField IsRequired="True" ErrorText="Indtast adgangskode"></RequiredField>
                                                </ValidationSettings>
                                            </dx:ASPxTextBox>
                                        </td>
                                    </tr>
                                    <tr>
                                        <td>
                                            <dx:ASPxLabel ID="lblRepeatPassword" runat="server" Text="Gentag adgangskode">
                                            </dx:ASPxLabel>
                                        </td>
                                        <td>
                                            <dx:ASPxTextBox ID="txtRepeatPassword" ClientInstanceName="txtRepeatPassword" Password="true" runat="server" Width="170px">
                                                <ValidationSettings CausesValidation="true" ValidationGroup="CreateUser" RequiredField-IsRequired="true" RequiredField-ErrorText="Gentag adgangskode" SetFocusOnError="true" ErrorDisplayMode="ImageWithTooltip">
                                                    <RequiredField IsRequired="True" ErrorText="Gentag adgangskode"></RequiredField>
                                                </ValidationSettings>
                                            </dx:ASPxTextBox>
                                        </td>
                                    </tr>
                                    <tr>
                                        <td colspan="2">
                                            <dx:ASPxCheckBox ID="cbEmailUserCreateInfo" ClientInstanceName="cbEmailUserCreateInfo" Text="Send email til bruger" runat="server">
                                            </dx:ASPxCheckBox>
                                        </td>
                                    </tr>
                                    <tr>
                                        <td colspan="2">
                                            <dx:ASPxButton ID="btnCreateCustomerUser" ClientInstanceName="btnCreateCustomerUser" ClientVisible="false" runat="server" Text="Opret" AutoPostBack="False" UseSubmitBehavior="False">
                                                <ClientSideEvents Click="function(s, e) { CreateCustomerUser(); }" />
                                            </dx:ASPxButton>
                                            <dx:ASPxButton ID="btnCreateInternalUser" ClientInstanceName="btnCreateInternalUser" ClientVisible="false" runat="server" Text="Opret" AutoPostBack="False" UseSubmitBehavior="False">
                                                <ClientSideEvents Click="function(s, e) { CreateInternalUser(); }" />
                                            </dx:ASPxButton>
                                        </td>
                                    </tr>
                                </table>
                                
                            </asp:Panel>

                        </dx:PanelContent>
                    </PanelCollection>
                </dx:ASPxCallbackPanel>
            </dx:PopupControlContentControl>
        </ContentCollection>
    </dx:ASPxPopupControl>

    <!-- Javascript for reset user -->
    <script language="javascript" type="text/javascript">

        // Function that handles reset user login in database
        function ResetUser() {

            // Validate values
            txtUserName.Validate();
            txtNewPassword.Validate();
            txtRepeatNewPassword.Validate();

            if (txtNewPassword.GetText() != txtRepeatNewPassword.GetText()) {
                alert("Adgangskode og gentag adgangskode er ikke ens");
                return;
            }

            var isFormValid = ASPxClientEdit.ValidateGroup("ResetUser");
            if (isFormValid) {

                var values = lblSelectedUserNameValue.GetText() + '|' + txtNewPassword.GetText() + '|' + cbEmailUserResetInfo.GetChecked();

                callbackResetUserPanel.PerformCallback(values);
            }
        }

        function OnCallbackResetUserComplete(s, e) {
            // Reset form
            // TODO: Write code

            // Hide modal popup
            pcResetUser.Hide();

            alert('Bruger login reset med ny adgangskode');
        }

        function ResetUserCallBackError(s, e) {
            // Hide modal popup
            pcResetUser.Hide();

            alert('Fejl opstod: ' + e.message);
        }

    </script>

    <!-- Modalpopup: Reset User -->
    <dx:ASPxPopupControl ID="pcResetUser" Modal="true" runat="server" Height="1px" AutoUpdatePosition="true"
        PopupHorizontalAlign="WindowCenter" PopupVerticalAlign="WindowCenter"
        AllowDragging="True" ClientInstanceName="pcResetUser" Left="100" Top="100"
        CloseAction="CloseButton" Width="175px" HeaderText="Reset bruger">
        <ContentCollection>
            <dx:PopupControlContentControl ID="PopupControlContentControl2" runat="server">
                <dx:ASPxCallbackPanel ID="callbackResetUserPanel" ClientInstanceName="callbackResetUserPanel" runat="server"
                    Width="320px" Height="100px" OnCallback="callbackResetUserPanel_Callback" RenderMode="Table">
                    <ClientSideEvents EndCallback="OnCallbackResetUserComplete" CallbackError="ResetUserCallBackError" />
                    <PanelCollection>
                        <dx:PanelContent ID="PanelContent2" runat="server">
                            
                            <asp:Panel runat="server" ID="Panel1">
                                
                                <table>
                                    <tr>
                                        <td>
                                            <dx:ASPxLabel ID="lblSelectedUserName" runat="server" Text="Brugernavn">
                                            </dx:ASPxLabel>
                                        </td>
                                        <td>
                                            <dx:ASPxLabel ID="lblSelectedUserNameValue" runat="server" Text="" ClientInstanceName="lblSelectedUserNameValue">
                                            </dx:ASPxLabel>
                                        </td>
                                    </tr>
                                    <tr>
                                        <td>
                                            <dx:ASPxLabel ID="lblNewPassword" runat="server" Text="Ny adgangskode">
                                            </dx:ASPxLabel>
                                        </td>
                                        <td>
                                            <dx:ASPxTextBox ID="txtNewPassword" ClientInstanceName="txtNewPassword" Password="true" runat="server" Width="170px">
                                                <ValidationSettings CausesValidation="true" ValidationGroup="ResetUser" RequiredField-IsRequired="true" RequiredField-ErrorText="Indtast ny ønsket adgangskode" SetFocusOnError="true" ErrorDisplayMode="ImageWithTooltip">
                                                    <RequiredField IsRequired="True" ErrorText="Indtast ny ønsket adgangskode"></RequiredField>
                                                </ValidationSettings>
                                            </dx:ASPxTextBox>
                                        </td>
                                    </tr>
                                    <tr>
                                        <td>
                                            <dx:ASPxLabel ID="lblRepeatNewPassword" runat="server" Text="Gentag ny adgangskode">
                                            </dx:ASPxLabel>
                                        </td>
                                        <td>
                                            <dx:ASPxTextBox ID="txtRepeatNewPassword" ClientInstanceName="txtRepeatNewPassword" Password="true" runat="server" Width="170px">
                                                <ValidationSettings CausesValidation="true" ValidationGroup="ResetUser" RequiredField-IsRequired="true" RequiredField-ErrorText="Gentag ny ønsket adgangskode" SetFocusOnError="true" ErrorDisplayMode="ImageWithTooltip">
                                                    <RequiredField IsRequired="True" ErrorText="Gentag ny ønsket adgangskode"></RequiredField>
                                                </ValidationSettings>
                                            </dx:ASPxTextBox>
                                        </td>
                                    </tr>
                                    <tr>
                                        <td colspan="2">
                                            <dx:ASPxCheckBox ID="cbEmailUserResetInfo" ClientInstanceName="cbEmailUserResetInfo" Text="Send email til bruger" runat="server">
                                            </dx:ASPxCheckBox>
                                        </td>
                                    </tr>
                                    <tr>
                                        <td colspan="2">
                                            <dx:ASPxButton ID="btnResetUser" ClientInstanceName="btnResetUser" runat="server" Text="Gem" AutoPostBack="False" UseSubmitBehavior="False">
                                                <ClientSideEvents Click="function(s, e) { ResetUser(); }" />
                                            </dx:ASPxButton>
                                        </td>
                                    </tr>
                                </table>
                                
                            </asp:Panel>

                        </dx:PanelContent>
                    </PanelCollection>
                </dx:ASPxCallbackPanel>
            </dx:PopupControlContentControl>
        </ContentCollection>
    </dx:ASPxPopupControl>

    <!-- Javascript for change user role assignment -->
    <script language="javascript" type="text/javascript">

        // Function that handles reset user login in database
        function ChangeRoleAssignment() {

//            // Validate values
//            txtUserName.Validate();
//            txtNewPassword.Validate();
//            txtRepeatNewPassword.Validate();

//            if (txtNewPassword.GetText() != txtRepeatNewPassword.GetText()) {
//                alert("Adgangskode og gentag adgangskode er ikke ens");
//                return;
//            }

//            var isFormValid = ASPxClientEdit.ValidateGroup("ResetUser");
//            if (isFormValid) {

//                var values = lblSelectedUserNameValue.GetText() + '|' + txtNewPassword.GetText();

//                callbackResetUserPanel.PerformCallback(values);
//            }
        }

        function OnCallbackChangeUserRoleAssignmentComplete(s, e) {
            // Reset form
            // TODO: Write code

            // Hide modal popup
            pcChangeUserRoleAssignment.Hide();

            alert('Bruger rolle fordeling blev gemt');
        }

        function ChangeUserRoleAssignmentCallBackError(s, e) {
            // Hide modal popup
            pcChangeUserRoleAssignment.Hide();

            alert('Fejl opstod: ' + e.message);
        }

    </script>

    <!-- Modalpopup: Change user role assignment -->
    <dx:ASPxPopupControl ID="pcChangeUserRoleAssignment" Modal="true" runat="server" Height="1px" AutoUpdatePosition="true"
        PopupHorizontalAlign="WindowCenter" PopupVerticalAlign="WindowCenter"
        AllowDragging="True" ClientInstanceName="pcChangeUserRoleAssignment" Left="100" Top="100"
        CloseAction="CloseButton" Width="175px" HeaderText="Rediger rolle tildeling">
        <ContentCollection>
            <dx:PopupControlContentControl ID="PopupControlContentControl3" runat="server">
                <dx:ASPxCallbackPanel ID="callbackChangeUserRoleAssignmentPanel" ClientInstanceName="callbackChangeUserRoleAssignmentPanel" runat="server"
                    Width="320px" Height="100px" OnCallback="callbackChangeUserRoleAssignmentPanel_Callback" RenderMode="Table">
                    <ClientSideEvents EndCallback="OnCallbackChangeUserRoleAssignmentComplete" CallbackError="ChangeUserRoleAssignmentCallBackError" />
                    <PanelCollection>
                        <dx:PanelContent ID="PanelContent3" runat="server">
                            
                            <asp:Panel runat="server" ID="Panel2">
                                
                                <table>
                                    <tr>
                                        <td>
                                            <dx:ASPxLabel ID="lblRoleAssignmentSelectedUserName" runat="server" Text="Brugernavn">
                                            </dx:ASPxLabel>
                                        </td>
                                        <td>
                                            <dx:ASPxLabel ID="lblRoleAssignmentSelectedUserNameValue" runat="server" Text="" ClientInstanceName="lblRoleAssignmentSelectedUserNameValue">
                                            </dx:ASPxLabel>
                                        </td>
                                    </tr>
                                    <tr>
                                        <td colspan="2">
                                            Funktionalitet endnu ikke implementeret
                                        </td>
                                    </tr>
                                    <tr>
                                        <td colspan="2">
                                            <dx:ASPxButton ID="btnChangeUserRoleAssignment" ClientInstanceName="btnChangeUserRoleAssignment" runat="server" Text="Gem" AutoPostBack="False" UseSubmitBehavior="False">
                                                <ClientSideEvents Click="function(s, e) { ChangeRoleAssignment(); }" />
                                            </dx:ASPxButton>
                                        </td>
                                    </tr>
                                </table>
                                
                            </asp:Panel>

                        </dx:PanelContent>
                    </PanelCollection>
                </dx:ASPxCallbackPanel>
            </dx:PopupControlContentControl>
        </ContentCollection>
    </dx:ASPxPopupControl>


</asp:Content>
